//
//  EOCDataModel.m
//  MacTestProject
//
//  Created by LiuLichen on 2022/4/26.
//

#import "EOCDataModel.h"

#import "EOCNetworkFetcher.h"
#import "EOCNetworkFetcherDelegate.h"

@interface EOCDataModel () <EOCNetworkFetcherDelegate>
@end

@implementation EOCDataModel {
    EOCNetworkFetcher* _networkFetcher;
    NSData* _fetchedData;
}

- (void) networkFetcher: (EOCNetworkFetcher*)fetcher
         didReceiveData: (NSData*)data {

}

- (void) networkFetcher: (EOCNetworkFetcher*)fetcher
       didFailWithError: (NSError *)error {

}

- (void) downloadData {
    NSURL* url = [[NSURL alloc] initWithString:@"https://www.example.com/something.dat"];
    _networkFetcher = [[EOCNetworkFetcher alloc] initWithURL:url];
    [_networkFetcher startWithCompletionHandler:^(NSData* data) {
        NSLog(@"Request url %@ finished", url);
        self->_fetchedData = data;
        self->_networkFetcher = nil;      // This is required, otherwise a circular reference will be formed.
    }];
}

@end
